package com.edu.exam.enums.common;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 严重程度枚举
 *
 * 统一的严重程度管理，用于各种需要级别控制的场景
 * 替代分散在各个实体中的重复严重程度定义
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-13
 */
public enum SeverityLevel implements BaseEnum {

    /**
     * 信息级别
     */
    INFO("INFO", "信息级别"),

    /**
     * 警告级别
     */
    WARNING("WARNING", "警告级别"),

    /**
     * 错误级别
     */
    ERROR("ERROR", "错误级别"),

    /**
     * 严重错误级别
     */
    CRITICAL("CRITICAL", "严重错误级别"),

    /**
     * 致命级别
     */
    FATAL("FATAL", "致命级别"),

    /**
     * 低风险级别
     */
    LOW("LOW", "低风险级别"),

    /**
     * 中风险级别
     */
    MEDIUM("MEDIUM", "中风险级别"),

    /**
     * 高风险级别
     */
    HIGH("HIGH", "高风险级别"),

    /**
     * 极高风险级别
     */
    EXTREME("EXTREME", "极高风险级别");

    private final String code;
    private final String description;

    SeverityLevel(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public static SeverityLevel fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("SeverityLevel code cannot be null or empty");
        }
        for (SeverityLevel severity : values()) {
            if (severity.getCode().equals(code)) {
                return severity;
            }
        }
        throw new IllegalArgumentException("Unknown SeverityLevel code: " + code);
    }

    public static SeverityLevel fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("SeverityLevel description cannot be null or empty");
        }
        for (SeverityLevel severity : values()) {
            if (severity.getDescription().equals(description)) {
                return severity;
            }
        }
        throw new IllegalArgumentException("Unknown SeverityLevel description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}